//
//  AppDelegate.m
//  Baymax
//
//  Created by jolin on 16/4/15.
//  Copyright © 2016年 jolin. All rights reserved.
//

#import "AppDelegate.h"
#import "IntroductionVC.h"
#import "AFNetworking.h"
#import "Header.h"
#import "LoginViewController.h"

#import "BMNavBar.h"

#import <SMS_SDK/SMSSDK.h>
#import "SuperID.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    NSLog(@"%@",NSHomeDirectory());
    [DataBaseTool initDataBase];
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    [self registThirdPart];
    //设置用户状态
    if (![[NSUserDefaults standardUserDefaults]valueForKey:@"accessToken"]) {
        [[NSUserDefaults standardUserDefaults]setValue:@"0" forKey:@"userStatus"];
    }
    [self setUpViewControllers];
    
    
    return YES;
}
#pragma mark - 注册第三方
- (void)registThirdPart {
    //shareSDK
    [SMSSDK registerApp:@"11e54335e7b28" withSecret:@"cbb1400a8c0f2793d50668cfae70f469"];
    
    //一登
    //向SuperID SDK 注册：AppID 和 AppSecret
    [[SuperID sharedInstance]registerAppWithAppID:@"SkRSMsLgzDseKrhMKb046wAr" withAppSecret:@"aqjS8efzLjsXHPDTSsIsvzOE"];
    
    //设置SuperID 的语言模式
    [SuperID setLanguageMode:SIDAutoMode];
    
    //设置SuperID Debugs 模式
    [SuperID setDebugMode:YES];
}
#pragma mark - 设置tableBar
- (void)setUpViewControllers {
    IntroductionVC *introVC = [[IntroductionVC alloc]init];
    [self.window addSubview:introVC.view];
    self.window.rootViewController = introVC;
    
    __block IntroductionVC *weakIntroVC = introVC;
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [weakIntroVC.view removeFromSuperview];
        //判断是否登录
//        NSInteger userStatus = [[[NSUserDefaults standardUserDefaults] valueForKey:@"userStatus"] intValue];
//        if(userStatus == 1) {
            UITabBarController *tabBarVC = [CommenTools setUpTabBar];
            self.window.rootViewController = tabBarVC;
            [self.window makeKeyAndVisible];
//        }else {
//            LoginViewController *loginVC = [[LoginViewController alloc]init];
//            UINavigationController *loginNav = [[UINavigationController alloc]initWithRootViewController:loginVC];
//            self.window.rootViewController = loginNav;
//            [self.window makeKeyAndVisible];
//        }
    });
    
    
}
#pragma mark - 监测网络状态
- (void)judgeNetWork {
    AFNetworkReachabilityManager *reachbilityManager = [AFNetworkReachabilityManager sharedManager];
    [reachbilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:{
                //未知网络
                NSLog(@"未知网络");
            }break;
            case AFNetworkReachabilityStatusNotReachable:{
                //没有联网
                NSLog(@"没有联网");
            }break;
            case AFNetworkReachabilityStatusReachableViaWWAN:{
                //手机网络
                NSLog(@"手机网络");
            }break;
            case AFNetworkReachabilityStatusReachableViaWiFi:{
                //wifi
                NSLog(@"wifi");
            }break;
            default:
                break;
        }
    }];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
